home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / VideoToolbox 95.04.18 / VideoToolboxSources / StringToDateAndSecs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-08  |  1.5 KB  |  50 lines  |  [TEXT/MMCC]

  1. /*
  2. StringToDateAndSecs.c
  3. Reads date such as "6/30/91", loads date structure, and returns secs since 1/1/1904.
  4. Returns NAN if date could not be read.
  5.  
  6.  
  7. HISTORY:
  8. 7/27/91 dgp    wrote it
  9. 8/5/91    dgp    made compatible with MPW C 3.2
  10. 8/24/91    dgp    Made compatible with THINK C 5.0.
  11. 12/13/92 dgp Removed obsolete support for THINK C 4.
  12. 5/28/94 dgp Renamed from "StringToDate" to "StringToDateAndSecs" to avoid
  13. conflict with Apple's new Universal Headers. Thanks to Bob Dougherty 
  14. (wolfgang@cats.ucsc.edu) for reporting the incompatibility.
  15. */
  16. #include "VideoToolbox.h"
  17. #include <Script.h>
  18. #include <math.h>
  19.  
  20. double StringToDateAndSecs(char *string,DateTimeRec *datePtr);
  21.  
  22. double StringToDateAndSecs(char *string,DateTimeRec *datePtr)
  23. {
  24.     LongDateRec longDate;
  25.     LongDateCvt longSecs;
  26.     double secs;
  27.     static DateCacheRecord theCache;
  28.     static Boolean firstTime=1;
  29.     int error;
  30.     long used;
  31.     
  32.     longDate.ld.era=longDate.ld.year=longDate.ld.month=longDate.ld.day=0;
  33.     longDate.ld.hour=longDate.ld.minute=longDate.ld.second=longDate.ld.dayOfWeek=0;
  34.     if(firstTime){
  35.         InitDateCache(&theCache);
  36.         firstTime=0;
  37.     }
  38.     error=String2Date(string,strlen(string),&theCache,&used,&longDate);
  39.     *datePtr=longDate.od.oldDate;
  40.     if(error)return NAN;
  41.     LongDate2Secs(&longDate,(LongDateTime *)&longSecs);
  42.     secs=HiWord(longSecs.hl.lHigh);
  43.     secs*=(double)0x10000;
  44.     secs+=(unsigned)LoWord(longSecs.hl.lHigh);
  45.     secs*=(double)0x10000;
  46.     secs+=(unsigned)HiWord(longSecs.hl.lLow);
  47.     secs*=(double)0x10000;
  48.     secs+=(unsigned)LoWord(longSecs.hl.lLow);
  49.     return secs;
  50. }